import { configToSearch, toSearchHandle } from '@/views/datacenter/business/utils/index'

const tableConfig = {
	stripe: true,
	border: true,
	maxHeight: '80vh',
	columns: [
		{ label: '证件号码', prop: 'idCard', plusXing: '2,2' },
		{ label: '服务对象', prop: 'oldmanName' },
		{ label: '联系方式', prop: 'oldmanPhone', plusXing: '5,2' },
		{ label: '入住信息', prop: 'lcc' },
		{ label: '养老机构', prop: 'organizationName' },
		// { label: '统一社会信用代码', prop: 'creditCode' },
		{ label: '账单年月', prop: 'billBelongMonth' },
		{ label: '办理人', prop: 'transactorName' },
		{ label: '办理时间', prop: 'transactDate' },
		{
			label: '是否可信',
			prop: 'isBelievable',
			custome: 'tag',
			dicData: [
				{ label: '否', value: 0, type: 'danger' },
				{ label: '是', value: 1, type: 'success' },
			],
		},
		{
			label: '操作',
			prop: 'menu',
			width: 300,
			fixed: 'right',
		},
	],
}

// 详情
export const detailConfig = {
	inline: false,
	showBtn: false,
	labelPosition: 'top',
	column: [
		{
			type: 'DividerHtml',
			modelValue: '服务对象信息',
			span: 24,
		},
		{
			label: '养老机构',
			prop: 'organizationName',
			type: 'text',
			maxlength: '50',
			showWordLimit: true,
			span: 12,
		},
		{
			label: '统一信用代码',
			prop: 'creditCode',
			type: 'text',
			maxlength: '18',
			showWordLimit: true,
			span: 12,
		},
		{
			label: '服务对象',
			prop: 'oldmanName',
			type: 'text',
			maxlength: '20',
			showWordLimit: true,
			span: 12,
		},
		{
			label: '证件号码',
			prop: 'idCard',
			type: 'text',
			maxlength: '18',
			showWordLimit: true,
			span: 12,
		},
		{
			label: '联系方式',
			prop: 'oldmanPhone',
			type: 'text',
			maxlength: '11',
			showWordLimit: true,
			span: 12,
		},
		{ label: '入住信息', prop: 'lcc', span: 12 },
		{
			type: 'DividerHtml',
			modelValue: '账单信息',
			span: 24,
		},
		{
			label: '账单年月',
			prop: 'billBelongMonth',
			type: 'month',
			format: 'YYYY年MM月',
			valueFormat: 'YYYYMM',
			span: 24,
		},
		{
			label: '账单计费开始日期',
			type: 'date',
			format: 'YYYY年MM月DD日',
			valueFormat: 'YYYY-MM-DD',
			prop: 'billStartDate',
			span: 12,
		},
		{
			label: '账单计费结束日期',
			type: 'date',
			format: 'YYYY年MM月DD日',
			valueFormat: 'YYYY-MM-DD',
			prop: 'billEndDate',
			span: 12,
		},
		{ label: '当月应缴费总金额', prop: 'receivableTotalAmount', append: '元', span: 12 },
		{
			label: '当月应缴费金额（床位费）',
			prop: 'receivableBedAmount',
			append: '元',
			span: 12,
		},
		{
			label: '当月应缴费金额（护理费）',
			prop: 'receivableNursingAmount',
			append: '元',
			span: 12,
		},
		{ label: '当月应缴费金额（餐费）', prop: 'receivableFoodAmount', append: '元', span: 12 },
		{
			label: '办理人',
			prop: 'transactorName',
			type: 'text',
			maxlength: '20',
			showWordLimit: true,
			span: 12,
		},
		{
			label: '办理时间',
			type: 'datetime',
			format: 'YYYY年MM月DD日 HH:mm:ss',
			valueFormat: 'YYYY-MM-DD HH:mm:ss',
			prop: 'transactDate',
			span: 12,
		},
		{
			label: '备 注',
			prop: 'receivableNote',
			type: 'text',
			maxlength: '140',
			showWordLimit: true,
			span: 24,
		},
	],
}
// 处理一下详情数据
const handleDetail = (column) => {
	if (column) {
		let list = JSON.parse(JSON.stringify(column))
		list.forEach((el, index) => {
			if (el.prop == 'lcc') {
				list.splice(index, 1)
				list.splice(
					index,
					0,
					{ label: '入住楼栋', prop: 'checkinBuilding', type: 'input', span: 6 },
					{ label: '入住楼层', prop: 'checkinFloor', type: 'input', span: 6 },
					{ label: '入住房间', prop: 'checkinRoom', type: 'input', span: 6 },
					{ label: '入住床位', prop: 'checkinBedCode', type: 'input', span: 6 }
				)
			}
		})
		return list
	}
}
const moreSearchConfig: any = {
	inline: true,
	showBtn: false,
	labelPosition: 'left',
	column: [...configToSearch(handleDetail(detailConfig.column))],
}
detailConfig.column.forEach((el) => {
	if (el.type != 'DividerHtml') {
		el.span = 8
	}
})
export const importConfig = {
	tabSteps: [
		{
			label: '下载模板',
			download: '下载模板',
			active: 1,
			rules: [
				{
					label: '下载最新导入模板。共1个：',
					children: [
						{
							label: '《老人账单记录》',
							link: true,
							url: 'view_dpElderlyReceivableRecord_downloadTemplate',
						},
					],
				},
			],
		},
		{
			label: '导入信息',
			description: '',
			uploadTip: '老人账单记录表',
			active: 2,
			url: 'view_dpElderlyReceivableRecord_import',
			code: 3026,
			rules: [
				{
					label: '导入规则说明:',
					children: [
						{
							label: '(1)导入模式为“覆盖导入”，待导入的信息会覆盖平台已存在的',
						},
					],
				},
			],
		},
	],
	dataType: 87,
}

export const baseConfig = {
	pageName: '老人账单记录',
	dictcodes: [],
	rowKey: 'id',
	tipLabel: 'oldmanName',
	paramsObj: {
		code: 3026,
	},
	exportMqTopic: '/ning/export/',
	api: {
		moreSearch: 'view_dpElderlyReceivableRecord_search',
		index: 'view_dpElderlyReceivableRecord_page',
		import: 'view_dpElderlyReceivableRecord_import',
		export: 'view_dpElderlyReceivableRecord_export',
		delete: 'view_dpElderlyReceivableRecord_del',
		detail: 'view_dpElderlyReceivableRecord_view',
		edit: 'view_dpElderlyReceivableRecord_edit',
	},
	auth: {
		index: 'view_dpElderlyReceivableRecord_page',
		// import: 'view_dpElderlyReceivableRecord_import',
		// export: 'view_dpElderlyReceivableRecord_export',
		delete: 'view_dpElderlyReceivableRecord_del',
		detail: 'view_dpElderlyReceivableRecord_view',
		edit: 'view_dpElderlyReceivableRecord_edit',
		mulitSet: 'mulitSet',
	},
	menuBtn: [
		{
			icon: 'detail',
			label: '详情',
			type: 'primary',
			operate: 'detail',
			auth: 'view_dpElderlyReceivableRecord_page',
			text: true,
			show: true,
		},
		{
			icon: 'edit',
			label: '编辑',
			type: 'primary',
			operate: 'edit',
			auth: 'view_dpElderlyReceivableRecord_edit',
			text: true,
			show: true,
		},
		{
			icon: 'delete',
			label: '删除',
			type: 'danger',
			operate: 'delete',
			auth: 'view_dpElderlyReceivableRecord_del',
			text: true,
			show: true,
		},
	],
	dialogConfig: {
		width: '80%',
	},
	moreSearchConfig,
	searchConfig: {
		inline: true,
		showBtn: true,
		labelPosition: 'left',
		column: [
			{ label: '证件号码', prop: 'idCard', type: 'input', span: 6 },
			{ label: '服务对象', prop: 'oldmanName', type: 'input', span: 6 },
			{
				label: '账单年月',
				prop: 'billBelongMonth',
				format: 'YYYY年MM月',
				valueFormat: 'YYYYMM',
				type: 'month',
				span: 6,
			},
			{ label: '养老机构', prop: 'organizationName', type: 'input', span: 6 },
		],
	},
	importConfig,
	tableConfig,
	detailConfig,
	formConfig: {
		...detailConfig,
		showBtn: true,
	},
	beforeOnLoadFormate: async (params) => {
		params = toSearchHandle(moreSearchConfig, {}, params)
		return Promise.resolve({
			...params,
		})
	},
	onLoadFormate: async (arr) => {
		const tableData = arr.map((item) => {
			return {
				...item,
				lcc: [item.checkinBuilding, item.checkinFloor, item.checkinRoom, item.checkinBedCode].filter(Boolean).join('-'),
			}
		})
		return Promise.resolve(tableData)
	},
}
